<ui:composition template="/WEB-INF/template/template.xhtml"
                xmlns="http://www.w3.org/1999/xhtml"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:rich="http://richfaces.org/rich"
                xmlns:a4j="http://richfaces.org/a4j"
                xmlns:sgbd="http://java.sun.com/jsf/composite/components">

    <ui:define name="title">Comptes</ui:define>

    <ui:define name="navigator">
        <sgbd:navigator comptes="active" />
    </ui:define>

    <ui:define name="content">
        <h:form>
            <h2>Liste des comptes</h2>
            <a4j:commandButton execute="@this"                               
                               render="addComptePopup" 
                               value="Ajouter"
                               rendered="#{loginBean.gestionnaire}"
                               oncomplete="#{rich:component('addComptePopup')}.show()">
                <f:setPropertyActionListener target="#{compteBean.current}" 
                                             value="#{null}" />
            </a4j:commandButton>
            <br />
            
            <rich:dataTable value="#{compteBean.all}" 
                            var="compte"
                            styleClass="dataTable"
                            rowClasses="even,odd"
                            id="comptesDataTable">
                <rich:column>
                    <f:facet name="header">
                        <h:outputText value="Name" />
                    </f:facet>
                    <h:outputText value="#{compte.name}" />
                </rich:column>
                <rich:column>
                    <f:facet name="header">
                        <h:outputText value="Serveur" />
                    </f:facet>
                    <h:outputText value="#{compte.server}" />
                </rich:column>
                <rich:column>
                    <f:facet name="header">
                        <h:outputText value="Port" />
                    </f:facet>
                    <h:outputText value="#{compte.portNumber}" />
                </rich:column>
                <rich:column>
                    <f:facet name="header">
                        <h:outputText value="Type" />
                    </f:facet>
                    <h:outputText value="#{compte.typeBDDid.typeBDD}" />
                </rich:column>
                <rich:column rendered="#{!loginBean.gestionnaire}">
                    <f:facet name="header">
                        <h:outputText value="Connexion" />
                    </f:facet>      
                    <a4j:commandLink styleClass="nodecor" 
                                     execute="@this"
                                     render="connectPopup"                                     
                                     oncomplete="#{rich:component('connectPopup')}.show()">
                        <f:setPropertyActionListener target="#{compteBean.current}" 
                                                     value="#{compte}" />
                        <h:graphicImage library="images" name="connect.gif" alt="Connexion" />
                    </a4j:commandLink>
                </rich:column>
                <rich:column rendered="#{loginBean.gestionnaire}">
                    <a4j:commandLink styleClass="nodecor" 
                                     execute="@this"
                                     render="comptesDataTable"
                                     action="#{compteBean.removeCompte()}">
                        <f:setPropertyActionListener target="#{compteBean.current}" 
                                                     value="#{compte}" />
                        <h:graphicImage library="images" name="delete.gif" />
                    </a4j:commandLink>
                </rich:column>
            </rich:dataTable>
            <ui:include src="connectPopup.xhtml">
                <ui:param name="id" value="connectPopup" />
            </ui:include>
            <ui:include src="addComptePopup.xhtml">
                <ui:param name="id" value="addComptePopup" />
            </ui:include>
        </h:form>
    </ui:define>
</ui:composition>
